import os
import sys
import numpy as np

loss = 1e-3 # 容忍偏差，一般fp16要求绝对误差和相对误差均不超过千分之一
minimum = 10e-10

def data_compare(file1, file2):
    input1 = np.fromfile(file1, dtype=np.float16)
    print("input1: ", input1)
    golden = np.sinh(input1).astype(np.float16)
    output = np.fromfile(file2, dtype=np.float16)
    print("output: ", output)
    print("-------------golden is :")
    print("golden: ", golden)

    different_element_results = np.isclose(
        output, golden,
        rtol=5e-2,
        atol=1e-3,
        equal_nan=True)
    different_element_indexes = np.where(
        different_element_results != np.array((True,)))[0]
    return 0 if different_element_indexes.size == 0 else 1


if __name__ == '__main__':
    intput_file1 = sys.argv[1]
    output_file = sys.argv[2]
    cmp_result = data_compare(intput_file1, output_file)

    if (cmp_result == 0):
        sys.exit(0)
    else:
        sys.exit(1)
